/*************************************************************************
> File Name: double_pointer.cpp
> Author: icebear
> Mail: 3322366195@qq.com
> Created Time: 2023-08-11 10:15:55
> Description: 多指针法
************************************************************************/

#include <iostream>
#include <vector>
using namespace std;
class Solution
{
public:
    string longestCommonPrefix(vector<string> &strs)
    {
        if (!strs.size())
        {
            return "";
        }
        int length = strs[0].size(); // 循环次数
        int count = strs.size();     // 个数
        for (int i = 0; i < length; ++i)
        {
            char c = strs[0][i];
            for (int j = 1; j < count; ++j)
            {
                if (i == strs[j].size() || strs[j][i] != c)
                // 出现不同或者字符串结束
                {
                    return strs[0].substr(0, i);
                }
            }
        }
        return strs[0];
    }
};
